<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      textarea {
        height: 120px;
        width: 300px;
      }
      ul {
        height: 480px;
        width: 300px;
        background-color: gray;
        overflow: auto;
      }
    </style>
  </head>
  <body>
    <div>
      <ul></ul>
      <textarea placeholder="按ctrl+回车发送消息"></textarea>
    </div>

    <script>
      var textarea = document.querySelector("textarea");
      textarea.onkeydown = function (evt) {
        var e = evt || window.event;
        console.log(e);
        if ((e.ctrlKey && e.keyCode == 13) || e.keyCode == 13) {
          var liObj = document.createElement("li");
          liObj.innerText = textarea.value;
          document.querySelector("ul").appendChild(liObj);
          textarea.value = null;
        }
      };
    </script>
  </body>
</html>
